package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    private static Student[] stus = new Student[5];

    public int findIndexById(String id) {
        int index = -1;
        for (int i = 0; i < 5; i++) {
            if (stus[i] != null && stus[i].getId().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public boolean addStudent(Student student) {
        int index = -1;
        for (int i = 0; i < 5; i++) {
            if (stus[i] == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            stus[index] = student;
            return true;
        }
    }

    public Student[] findAllStudent() {
        return stus;
    }

    public void deleteStudent(String id) {
        stus[findIndexById(id)] = null;
    }

    public void updateStudent(String id, Student s) {
        stus[findIndexById(id)] = s;
    }
}
